package rabbitmq

import (
	"fmt"
	"gin-easy/pkg/zap_log"
	"github.com/streadway/amqp"
)

var RabbitmqCh *amqp.Channel
var Rabbitmq *amqp.Connection

/*
*
初始化
*/
func Setup() {
	Rabbitmq, err := amqp.Dial(fmt.Sprintf("amqp://admin:123456@localhost:5672/"))
	failOnError(err, "Failed to connect to RabbitMQ")
	ch, err := Rabbitmq.Channel()
	failOnError(err, "Failed to open a channel")
	RabbitmqCh = ch
}

func failOnError(err error, msg string) {
	if err != nil {
		zap_log.Lg.Fatal(fmt.Sprintf("%s: %s", msg, err))
	}
}
